package com.jetpackmvp

import android.app.Application
import android.os.Build
import android.os.StrictMode
import leakcanary.RefWatcher


/**
 * @author: GY.LEE
 * @date: 2019-06-05
 */
class JetPackMvpApplication : Application() {

    lateinit var refWatcher: RefWatcher


    override fun onCreate() {
        super.onCreate()
        application = this
        setupLeakCanary()
    }

    private fun setupLeakCanary() {
        enabledStrictMode()
    }

    private fun enabledStrictMode() {
        val builder = StrictMode.ThreadPolicy.Builder()
            .detectDiskWrites()
            .detectNetwork()
            .detectCustomSlowCalls()
            .penaltyLog()
            .penaltyDeath()
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            builder.detectResourceMismatches()
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            builder.detectUnbufferedIo()
        }
        StrictMode.setThreadPolicy(builder.build())
    }

    companion object {
        lateinit var application: JetPackMvpApplication
    }
}